<template>
	<view>
		<block v-if="address">
			<view class="m-title">
				<text>当前定位</text>
			</view>
			<view class="m-tip-view" @click="selectAreaFun({title:city})">
				<view class="m-tip-city">
					<image src="@/static/address.png" mode=""></image>
					<text>{{city}}</text>
				</view>
				<view class="m-tip-address">
					<text>{{address}}</text>
				</view>
			</view>
		</block>
		<view class="m-title">
			<text>热门城市</text>
		</view>
		<view class="m-card">
			<view class="m-list">
				<view class="m-item" @click="selectAreaFun(item)" v-for="(item,index) in list" :key="index">
					<text>{{item.title}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var QQMapWX = require('../../common/libs/qqmap-wx-jssdk.min.js');
	var qqmapsdk;
	const key = 'XPXBZ-6PY3K-GGCJK-AOEYP-JM575-5FBIP'
	
	export default {
		data() {
			return {
				address:'',
				city:'',
				list:[]
			};
		},
		onLoad() {
			qqmapsdk = new QQMapWX({
				key: key
			});
			this.getDataFun()
			this.getLocationFun()
		},
		onUnload() {
			// 页面卸载时设置插件选点数据为null，防止再次进入页面，geLocation返回的是上次选点结果
			// chooseLocation.setLocation(null);
		},
		methods:{
			getLocationFun(){
				qqmapsdk.reverseGeocoder({
					success: (e) => {
						if (e.status === 0) {
							let d = e.result.address_reference
							for(let i in d){
								if(d[i].title){
									this.address = d[i].title
									break;
								}
							}
							this.city = e.result.ad_info.city.replace('市','')
						}
					},
					fail:(e)=>{

					}
				})
			},
			getDataFun(){
				this.$http.getJson('hotal_channel',{parentId:0}).then(res=>{
					if(res.code == 1){
						let list = res.data
						this.list = list
					}
				})
			},
			selectAreaFun(item){
				this.$u.vuex('vuexCity',item.title)
				this.$nextTick(()=>{
					uni.$emit('resetListFun','area')
					this.to_back()
				})
				
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #fff;
	}
	.m-title{
		font-size: 24rpx;
		color: #8F6F4C;
		font-weight: 800;
		padding: 12rpx 25rpx;
	}
	.m-tip-view{
		display: flex;
		padding-left: 20rpx;
		padding-top: 20rpx;
		padding-bottom: 30rpx;
		.m-tip-city{
			display: flex;
			align-items: center;
			height: 72rpx;
			background: #F6F6F6;
			padding: 0 20rpx;
			border-radius: 8rpx;
			font-size: 28rpx;
			color: #8F6F4C;
			image{
				width: 30rpx;
				height: 30rpx;
				margin-right: 15rpx;
			}
		}
		.m-tip-address{
			display: flex;
			align-items: center;
			height: 72rpx;
			background: #F6F6F6;
			padding: 0 20rpx;
			border-radius: 8rpx;
			font-size: 28rpx;
			color: #8F6F4C;
			margin-left: 16rpx;
			image{
				width: 30rpx;
				height: 30rpx;
				margin-right: 15rpx;
			}
		}
	}
.m-card{
	background: #fff;
	padding: 25rpx 0 5rpx 25rpx;
	.m-list{
		display: flex;
		flex-wrap: wrap;
		.m-item{
			width: 200rpx;
			height: 72rpx;
			background: #F6F6F6;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			text-align: center;
			line-height: 72rpx;
			margin-right: 20rpx;
			margin-bottom: 20rpx;
		}
	}
}
</style>
